<template>
	<!-- 资料详情 -->
	<div class="tobeDone">
		<tableIndex
			:tableData="tableData"
			:tableHead="tableHead"
			:isIndex="true"
			:isSelection="true"
			:isRadio="false"
			:fields="state.fields"
			:height="500"
			ref="tableRef"
			:page="state.page"
			@selectChange="selectChange"
			@searchList="searchList"
			@page-change="pageChange"
			@resetList="resetList"
		>
			<template #right-btn>
				<div style="float: right">
					<el-button size="small" plain class="button_edit" @click="onExport"
						>导出</el-button
					>
				</div>
			</template>
			<template #operate>
				<el-table-column label="操作" width="200" fixed="right">
					<template #default="{ row }">
						<el-button
							size="small"
							class="button_view"
							type="primary"
							@click="viewHandel(row)"
							>查看</el-button
						>
					</template>
				</el-table-column>
			</template>
		</tableIndex>
	</div>
</template>

<script setup>
import tableIndex from "@/components/table/index.vue";
import { exportExcelFile } from "@/common/utils/GlobalUtils";
import { projectFileApi } from "@/api/investment";
import { ref, onMounted, reactive } from "vue";
import { useRouter, useRoute } from "vue-router";
let Router = useRouter();
let route = useRoute();

const state = reactive({
	page: {
		page: 1,
		pageSize: 50,
		total: 0,
	},
	fields: [{ key: "keywords", label: "关键字", type: "input", placeholder: "请输入关键字" }],
});
// const info = ref(null)
const tableData = ref([]);
const tableHead = ref([
	{
		prop: "projectName",
    label: "项目",
    minWidth: 100
	},
	{
		prop: "fileNum",
    label: "资料数",
    minWidth: 100
	},
	{
		prop: "createTime",
    label: "创建时间",
    minWidth: 150
	},
	{
		prop: "responsibleUserName",
    label: "创建人",
    minWidth: 100
	},
]);

const viewHandel = (row) => {
	Router.push({
		path: `/investmentProjectManagement/investmentProjects/investmentProjectInformation/informationDetails/projectId=${row.projectId}&projectTypeId=${row.projectTypeId}`,
	});
};

//搜索接口请求
const searchList = (e) => {
	getPage(e);
};
const resetList = (e) => {
	getPage();
};
//分页变化
const pageChange = (e) => {
	state.page.page = e.page;
	state.page.pageSize = e.limit;
	getPage();
};
const getPage = (e) => {
	let obj = {
		pageNum: state.page.page,
		pageSize: state.page.pageSize,
		param: {
			...e,
		},
	};
	projectFileApi.getProjectPageList(obj).then((res) => {
		if (res.code == "200") {
			tableData.value = res.data.content;
			state.page.total = res.data.totalSize;
		}
	});
};
const tableRef = ref(null);
const onExport = () => {
	const obj = {
		...tableRef.value.getSearchData(),
	};

	projectFileApi.projectExport(obj.keywords || "").then((res) => {
		exportExcelFile(res, "项目资料管理");
	});
};

const selectChange = () => {

}

onMounted(() => {
	getPage();
});
</script>

<style lang="scss" scoped>
.tobeDone {
	width: 100%;
	height: 100%;
}
</style>
